package cn.stu.system.controller;

import cn.stu.common.utils.ApiData;
import cn.stu.framework.entity.Announcement;
import cn.stu.framework.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 公告控制器
 *
 * @author wangxiaoyang
 * @date 2023/08/03
 * @since 2020/11/11
 */
@RestController
@RequestMapping("/announcements")
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;


    /**
     * 名单公布
     *
     * @param pageNumber 页码
     * @param pageSize   页面大小
     * @return {@link ApiData}
     */
    @GetMapping
    public ApiData listAnnouncement(@RequestParam(defaultValue = "1") Long pageNumber, @RequestParam(defaultValue = "10") Long pageSize) {
        return announcementService.list(pageNumber, pageSize);
    }

    /**
     * 创建声明
     *
     * @param announcement 公告
     * @return {@link ApiData}
     */
    @PostMapping
    public ApiData createAnnouncement(@RequestBody @Validated({Announcement.Create.class}) Announcement announcement) {
        return announcementService.announcementCreate(announcement);
    }

    /**
     * 更新公告
     *
     * @param announcement 公告
     * @return {@link ApiData}
     */
    @PutMapping
    public ApiData updateAnnouncement(@RequestBody @Validated({Announcement.Update.class}) Announcement announcement) {
        return announcementService.announcementUpdate(announcement);
    }

    /**
     * 删除公告
     *
     * @param id id
     * @return {@link ApiData}
     */
    @DeleteMapping("{id}")
    public ApiData deleteAnnouncement(@PathVariable Long id) {
        return announcementService.announcementDelete(id);
    }

}